<?php

namespace App\Http\Controllers;

use App\Person;
use Illuminate\Http\Request;

class PersonController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $data = Person::where([]) -> get();
        return view('listp', ['data'=>$data]);
        // view
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('addp'); // person/create => 指向视图名addp.blade.php
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $res = Person::create($request->all());
//        dd($res);
        return 'store';
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        dd($id);
        return 'show';
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $data = Person::find($id);
        return view('editp',['id'=>$id, 'data'=>$data]);
    }

    /**
     * Update the specified resource in storage.
     * Request -- use 引入
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, Person $person)
    {
//        dd($request->all());
//        dd($person);
        $person->name = $request->name;
        $person->password = $request->password;
        $res = $person->save();
        dd($res);
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
//    public function destroy($id)
//    {
//        $person = Person::find($id);
//        $res = $person->delete();
//        dd($res);
//    }
    public function del($id)
    {
        $person = Person::find($id);
        $res = $person->delete();
        dd($res);
    }
}
